package com.sgb.goods.viewmodel;

import androidx.databinding.ObservableField;

import com.alibaba.android.arouter.launcher.ARouter;
import com.sgb.goods.BR;
import com.sgb.goods.R;
import com.sgb.goods.api.GoodsCallBack;
import com.sgb.goods.api.GoodsNet;
import com.sgb.goods.entity.ReceiptGoodsDelEntity;
import com.sgb.goods.utils.Constants;
import com.sgb.goods.utils.base.adapter.BaseCommonAdapter;
import com.sgb.goods.utils.base.viewmodel.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.util.MLog;
import com.swgk.core.util.StringUtil;

/**
 * 订单详情-收货详情
 * @author cyj
 */
public class ReceiptGoodsDetailsModel extends BaseViewModel {

    public BaseCommonAdapter<ReceiptGoodsDelEntity.ListDTO> adapter;
    public ObservableField<ReceiptGoodsDelEntity> receiptGoodsDelEntity = new ObservableField<>(new ReceiptGoodsDelEntity());
//    public MutableLiveData<ReceiptGoodsDelEntity> requireData = new MutableLiveData<>();

    public ReceiptGoodsDetailsModel() {
        adapter = new BaseCommonAdapter<>(R.layout.goods_item_receipt_goods_details, BR.entity);
    }

    /** 查询收货详情 */
    public void getReceiveDetails(String receiveId) {
        showLoading();
        GoodsNet.getInstance().getGoodsApi().getReceiveDetails(receiveId).enqueue(new GoodsCallBack<BaseEntity<ReceiptGoodsDelEntity>>() {
            @Override
            public void onSuccess(BaseEntity<ReceiptGoodsDelEntity> data) {
                adapter.setNewData(data.getData().list);
//                requireData.postValue(data.getData());
                receiptGoodsDelEntity.set(data.getData());
            }
        });
    }

    /** 点击事件-预览 */
    public void preViewForOnClick(String fileUrl) {
        if(StringUtil.isEmpty(fileUrl)) {
            MLog.e("ReceiptGoodsDetailsModel->preViewForOnClick() ", "fileUrl is null");
           return;
        }
        ARouter.getInstance().build(Constants.ARouter.AR_PREVIEW)
                .withString("url", fileUrl)
                .withString("fileUrl", null)
                .navigation();
    }
}
